﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using BusinessModel;
using EntityDataModel;
using System.ComponentModel;
using System.Data.Objects.DataClasses;

namespace Controller.DataProvider
{
    public class BuyOrderDetailPro : GenericProvider<BuyOrderDetail>
    {
        public BuyOrderDetailPro()
        {
            EntityName = "Tbl_BuyOrderDetail";
        }

        #region override Methods
        //----------------------------------------
        public override EntityObject CreateEntity()
        {
            return new Tbl_BuyOrderDetail();
        }
        //----------------------------------------
        public override BuyOrderDetail CreateModel()
        {
            return new BuyOrderDetail();
        }
        //----------------------------------------
        public override void ToEntity(BuyOrderDetail pModel, EntityObject pEntity, params EnumFieldCopy[] pEnumFieldCopys)
        {
            Tbl_BuyOrderDetail oEntity = pEntity as Tbl_BuyOrderDetail;
            oEntity.BuyOrderId = pModel.BuyOrderId;
            oEntity.ProductId = pModel.ProductId;
            oEntity.UnitId = pModel.UnitId;
            oEntity.SupplierId = pModel.SupplierId;
            oEntity.DiscountTypeId = pModel.DiscountTypeId;
            oEntity.DiscountValue = pModel.DiscountValue;
            oEntity.Quantity = pModel.Quantity;
            oEntity.BuyPriceUnit = pModel.BuyPriceUnit;
            oEntity.SalePriceUnit = pModel.SalePriceUnit;
            oEntity.IsConsign = pModel.IsConsign;
            oEntity.BuyDate = pModel.BuyDate;
            oEntity.Note = pModel.Note;
            pEnumFieldCopys.ToList().ForEach((item) =>
            {
                switch (item)
                {
                    case EnumFieldCopy.Id:
                        oEntity.Id = pModel.Id;
                        break;
                    case EnumFieldCopy.All:
                        oEntity.Id = pModel.Id;
                        break;
                }
            });
        }
        //----------------------------------------
        public override void ToModel(EntityObject pEntity, BuyOrderDetail pModel, params EnumFieldCopy[] pEnumFieldCopys)
        {
            Tbl_BuyOrderDetail oEntity = pEntity as Tbl_BuyOrderDetail;
            pModel.BuyOrderId = oEntity.BuyOrderId;
            pModel.ProductId = oEntity.ProductId;
            pModel.UnitId = oEntity.UnitId;
            pModel.SupplierId = oEntity.SupplierId;
            pModel.DiscountTypeId = oEntity.DiscountTypeId;
            pModel.DiscountValue = oEntity.DiscountValue;
            pModel.Quantity = oEntity.Quantity;
            pModel.BuyPriceUnit = oEntity.BuyPriceUnit;
            pModel.SalePriceUnit = oEntity.SalePriceUnit;
            pModel.IsConsign = oEntity.IsConsign;
            pModel.BuyDate = oEntity.BuyDate;
            pModel.Note = oEntity.Note;
            pEnumFieldCopys.ToList().ForEach((item) =>
            {
                switch (item)
                {
                    case EnumFieldCopy.Id:
                        pModel.Id = oEntity.Id;
                        break;
                    case EnumFieldCopy.All:
                        pModel.Id = oEntity.Id;
                        break;
                }
            });
        }
        #endregion override Methods
    }
}
